package siediyu.tutorialmod.block;

import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroups;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.Identifier;
import siediyu.tutorialmod.ToturialModClient;
import siediyu.tutorialmod.Tutorial;

public class ModBlocks {

    //创建粉宝石方块
    //AbstractBlock.Settings.create()用于创建方块设置
    //strength(4.0f)硬度,应该和挖掘时间有关
    //requiresTool()需要的工具,这里没设置
    //sounds()声音,这里使用的是紫水晶的声音
    public static final Block PINK_GARNET_BLOCK = registerBlock("pink_garnet_block",
            new Block(AbstractBlock.Settings.create().strength(4.0f).requiresTool()
                    .sounds(BlockSoundGroup.AMETHYST_BLOCK)));

    //创建石榴石矿
    public static final Block RAW_PINK_GARNET_BLOCK = registerBlock("raw_pink_garnet_block",
            new Block(AbstractBlock.Settings.create().strength(3.0f).requiresTool()));

    //辅助方法2
    //方法一是将方块注册到ITEM中
    //方法二是将方块注册到BLOCK中(方法1已经在方法2中执行)
    private static Block registerBlock(String name, Block block) {
        registerModBlockItem(name, block);
        return Registry.register(Registries.BLOCK,Identifier.of(Tutorial.MOD_ID,name),block);
    }

    //辅助方法1--此处选择的是Minecraft的Block
    private static void registerModBlockItem(String name, Block block) {
        //把第三个参数用第二个参数生成的标识符注册到ITEM注册表,详细解释看ModItems里面
        //稍微有些区别,但大同小异
        Registry.register(Registries.ITEM, Identifier.of(Tutorial.MOD_ID, name),
                new BlockItem(block, new Item.Settings()));
    }


    //先写一个注册器
    public static void registerBlocks() {
        //日志输出
        Tutorial.LOGGER.info("Registering Mod Blocks" + Tutorial.MOD_ID);

        //将粉宝石方块添加到物品栏(粉宝石方块需要添加到构建块这一类)
        ItemGroupEvents.modifyEntriesEvent(ItemGroups.BUILDING_BLOCKS).register(
                entries -> {
                    entries.add(PINK_GARNET_BLOCK);
                    entries.add(RAW_PINK_GARNET_BLOCK);
                }
        );
    }
}
